package com.design.singleton.lazy;

/**
 * @auther LiZiBa
 * @date 2020/8/8 10:14
 * @description: 静态内部类实现懒汉单利模式
 *               优点：静态内部类语法优点，只有在使用的时候才加载，无内存浪费和性能问题，写法优雅
 *               缺点：能被反射破坏单例
 **/
public class StaticInnerClassLazySingleton {

    private StaticInnerClassLazySingleton(){

        if(LazyHolder.INSTACNE != null){
            throw new RuntimeException("禁止非法访问！");
        }
    }

    private static StaticInnerClassLazySingleton getInstance(){

       return LazyHolder.INSTACNE;
    }

    private static class LazyHolder {

        private static final StaticInnerClassLazySingleton INSTACNE = new StaticInnerClassLazySingleton();

    }
}
